package cn.sumpu.app.guoguojie.dao.impl;

import java.util.List;

import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import cn.sumpu.app.guoguojie.dao.ExperDao;
import cn.sumpu.app.guoguojie.domain.Learning;
import cn.sumpu.app.guoguojie.domain.Work;
import cn.sumpu.app.guoguojie.exception.AppBusinessException;

public class ExperDaoImpl extends SqlSessionDaoSupport implements ExperDao {

	private static Logger logger = LoggerFactory.getLogger(ExperDaoImpl.class);

	@SuppressWarnings("unchecked")
	@Override
	public List<Learning> getLearningList(String member)
			throws AppBusinessException {
		try {
			return getSqlSession().selectList("cn.sumpu.app.guoguojie.persistence.ExperMapper.getLearningList",member);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("query getLearningList failure.", e);
			}
			throw new AppBusinessException("query getLearningList failure.", e);
		}
	}
	
	

	@Override
	public Learning getLearningById(Integer id) throws AppBusinessException {
		try {
			return (Learning) getSqlSession().selectOne("cn.sumpu.app.guoguojie.persistence.ExperMapper.getLearningById",id);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("query getLearningById failure.", e);
			}
			throw new AppBusinessException("query getLearningById failure.", e);
		}
	}



	@Override
	public void insertLearning(Learning learing) throws AppBusinessException {
		try {
			getSqlSession().insert("cn.sumpu.app.guoguojie.persistence.ExperMapper.insertLearning",learing);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("insertLearning failure.", e);
			}
			throw new AppBusinessException("insertLearning failure.", e);
		}
	}

	@Override
	public void deleteLearning(String member) throws AppBusinessException {
		try {
			getSqlSession().delete("cn.sumpu.app.guoguojie.persistence.ExperMapper.deleteLearning",member);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("deleteLearning failure.", e);
			}
			throw new AppBusinessException("deleteLearning failure.", e);
		}
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Work> getWorkList(String member)
			throws AppBusinessException {
		try {
			return getSqlSession().selectList("cn.sumpu.app.guoguojie.persistence.ExperMapper.getWorkList",member);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("query getWorkList failure.", e);
			}
			throw new AppBusinessException("query getWorkList failure.", e);
		}
	}

	@Override
	public void insertWork(Work work) throws AppBusinessException {
		try {
			getSqlSession().insert("cn.sumpu.app.guoguojie.persistence.ExperMapper.insertWork",work);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("insertWork failure.", e);
			}
			throw new AppBusinessException("insertWork failure.", e);
		}
	}

	@Override
	public void deleteWork(String member) throws AppBusinessException {
		try {
			getSqlSession().delete("cn.sumpu.app.guoguojie.persistence.ExperMapper.deleteWork",member);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("deleteWork failure.", e);
			}
			throw new AppBusinessException("deleteWork failure.", e);
		}
	}



	@Override
	public void updateLearning(Learning learning) throws AppBusinessException {
		try {
			getSqlSession().update("cn.sumpu.app.guoguojie.persistence.ExperMapper.updateLearning",learning);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("updateLearning failure.", e);
			}
			throw new AppBusinessException("updateLearning failure.", e);
		}
	}



	@Override
	public void deleteLearningById(Integer id) throws AppBusinessException {
		try {
			getSqlSession().delete("cn.sumpu.app.guoguojie.persistence.ExperMapper.deleteLearningById",id);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("deleteLearningById failure.", e);
			}
			throw new AppBusinessException("deleteLearningById failure.", e);
		}
		
	}



	@Override
	public void updateWork(Work work) throws AppBusinessException {
		try {
			getSqlSession().update("cn.sumpu.app.guoguojie.persistence.ExperMapper.updateWork",work);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("updateWork failure.", e);
			}
			throw new AppBusinessException("updateWork failure.", e);
		}
		
		
	}



	@Override
	public void deleteWorkById(Integer id) throws AppBusinessException {
		try {
			getSqlSession().delete("cn.sumpu.app.guoguojie.persistence.ExperMapper.deleteWorkById",id);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("deleteWorkById failure.", e);
			}
			throw new AppBusinessException("deleteWorkById failure.", e);
		}
		
		
	}



	@Override
	public Work getWorkById(Integer id) throws AppBusinessException {
		try {
			return	(Work) getSqlSession().selectOne("cn.sumpu.app.guoguojie.persistence.ExperMapper.getWorkById",id);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("getWorkById failure.", e);
			}
			throw new AppBusinessException("getWorkById failure.", e);
		}
	}

	
	

}
